package org.mybatis.saldi;

import it.widgets.client.beans.Saldo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.mybatis.mappers.SaldoMapper;

@Aspect
public class BusinessLogicSaldoAsp {
	@Before("execution(public * org.mybatis.saldi.*.*(..))")
	public void beforeMethod(JoinPoint jp) {
		System.out.println("#S# before " + jp.getSignature().getName());
		BusinessLogicSaldo bs = (BusinessLogicSaldo) jp.getTarget();
		bs.openSession();
		bs.setMapper(SaldoMapper.class);
	    System.out.println("#E# before " + jp.getSignature().getName());
	}
	
	@After("execution(public * org.mybatis.saldi.*.*(..))")
	public void afterMethod(JoinPoint jp) {
		System.out.println("#S# After " + jp.getSignature().getName());
		BusinessLogicSaldo bs = (BusinessLogicSaldo) jp.getTarget();
		bs.commitSession();
		bs.closeSession();
	    System.out.println("#E# After " + jp.getSignature().getName());
	}
  
  @AfterReturning(
		  pointcut = "execution(public * org.mybatis.saldi.*.calcolaSaldo())",
		  returning = "saldo")
  public void afterReturning2(JoinPoint jp, Saldo saldo){
	  System.out.println("#S# AfterReturning " + jp.getSignature().getName());
	  System.out.println("#######################################");
	  System.out.println( saldo.toString() );	
	  System.out.println("#######################################");	
  }
}
